home *** CD-ROM | disk | FTP | other *** search
Wrap
RRRRWWWWTTTTiiiimmmmeeee((((3333CCCC++++++++)))) RRRRWWWWTTTTiiiimmmmeeee((((3333CCCC++++++++)))) NNNNaaaammmmeeee RWTime - Rogue Wave library class SSSSyyyynnnnooooppppssssiiiissss #include <rw/rwtime.h> RWTime a; // Construct with current time DDDDeeeessssccccrrrriiiippppttttiiiioooonnnn Class RRRRWWWWTTTTiiiimmmmeeee represents a time, stored as the number of seconds since 00:00:00 January 1, 1901 UTC. See Section 8 for how to set the time zone for your compiler. Failure to do this may result in UTC (GMT) times being wrong. Output formatting is done using an RRRRWWWWLLLLooooccccaaaalllleeee object. The default locale formats according to U.S. conventions. Note that because the default constructor for this class creates an instance holding the current date and time, constructing a large array of RRRRWWWWTTTTiiiimmmmeeee may be slow. RWTime v[5000]; // Figures out the current time 5000 times Those with access to the C++ Standard Library-based versions of the TTTToooooooollllssss....hhhh++++++++ template collections should consider the following: // Figures out the current time just once: RWTValOrderedVector<RWTime> v(5000, RWTime()); Thanks to the smart allocation scheme of the standard collections, the above declaration will result in only one call to the default constructor followed by 5000 invocations of the copy constructor. In the case of RRRRWWWWTTTTiiiimmmmeeee,,,, the copy constructor amounts to an assignment of one lllloooonnnngggg to another, resulting in faster creation than the simple array. PPPPeeeerrrrssssiiiisssstttteeeennnncccceeee Simple EEEExxxxaaaammmmpppplllleeee This example constructs a current time, and the time when Daylight-Saving Time starts in the year 1990. It then prints them out. PPPPaaaaggggeeee 1111 RRRRWWWWTTTTiiiimmmmeeee((((3333CCCC++++++++)))) RRRRWWWWTTTTiiiimmmmeeee((((3333CCCC++++++++)))) #include <rw/rwtime.h> #include <rw/rwdate.h> #include <rw/rstream.h> main(){ RWTime t; // Current time RWTime d(RWTime::beginDST(1990, RWZone::local())); cout << "Current time: " << RWDate(t) << " " << t << endl; cout << "Start of DST, 1990: " << RWDate(d) << " " << d << endl; } PPPPrrrrooooggggrrrraaaammmm oooouuuuttttppppuuuutttt Current time: 03/22/91 15:01:40 Start of DST, 1990: 05/01/90 02:00:00 PPPPuuuubbbblllliiiicccc CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrrssss RRRRWWWWTTTTiiiimmmmeeee(); Default constructor. Constructs a time with the present time. RRRRWWWWTTTTiiiimmmmeeee(const RWTime&); Copy constructor. RRRRWWWWTTTTiiiimmmmeeee(unsigned long s); Constructs a time with ssss seconds since 00:00:00 January 1, 1901 UTC. If ssss========0000, an invalid time is constructed. Note that for small ssss this may be prior to January 1, 1901 in your time zone. RRRRWWWWTTTTiiiimmmmeeee(unsigned hour, unsigned minute, unsigned second=0, const RWZone& zone = RWZone::local()); Constructs a time with today's date, and the specified hour, minute, and second, relative to the time zone zzzzoooonnnneeee, which defaults to local time. RRRRWWWWTTTTiiiimmmmeeee(const RWDate& date, unsigned hour = 0, unsigned minute = 0,unsigned second = 0, const RWZone& = RWZone::local()); PPPPaaaaggggeeee 2222 RRRRWWWWTTTTiiiimmmmeeee((((3333CCCC++++++++)))) RRRRWWWWTTTTiiiimmmmeeee((((3333CCCC++++++++)))) Constructs a time for a given date, hour, minute, and second, relative to the time zone zzzzoooonnnneeee, which defaults to local time. Note that the maximum RRRRWWWWTTTTiiiimmmmeeee is much sooner than maximum RRRRWWWWDDDDaaaatttteeee. (In fact, it is on Feb. 5, 2037 for platforms with 4-byte lllloooonnnnggggs.) This is a consequence of the fact that RRRRWWWWTTTTiiiimmmmeeee counts seconds while RRRRWWWWDDDDaaaatttteeee only deals with full days. RRRRWWWWTTTTiiiimmmmeeee(const struct tm*, const RWZone& = RWZone::local()); Constructs a time from the ttttmmmm____yyyyeeeeaaaarrrr, ttttmmmm____mmmmoooonnnn, ttttmmmm____mmmmddddaaaayyyy, ttttmmmm____hhhhoooouuuurrrr, ttttmmmm____mmmmiiiinnnn, and ttttmmmm____sssseeeecccc components of the ssssttttrrrruuuucccctttt ttttmmmm argument. These components are understood to be relative to the time zone zzzzoooonnnneeee, which defaults to local time. Note that the numbering of months and years in a ssssttttrrrruuuucccctttt ttttmmmm differs from that used in RRRRWWWWTTTTiiiimmmmeeee arguments. RRRRWWWWTTTTiiiimmmmeeee(const RWDate& date, const RWCString& str, const RWZone& zone = RWZone::local(), const RWLocale& locale = RWLocale::global()); Constructs a time for the given date, extracting the time from the string ssssttttrrrr. The string ssssttttrrrr should contain only the time. The time is understood to be relative to the time zone zzzzoooonnnneeee, which defaults to local time. The specified locale is used for formatting information . Use function iiiissssVVVVaaaalllliiiidddd(((()))) to check the results. Note: not all time string errors can be detected by this function. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr OOOOppppeeeerrrraaaattttoooorrrrssss RWTime& ooooppppeeeerrrraaaattttoooorrrr====(const RWTime&); Assignment operator. RWTime ooooppppeeeerrrraaaattttoooorrrr++++++++(); Prefix increment operator. Add one second to self, then return the results. RWTime ooooppppeeeerrrraaaattttoooorrrr--------(); Prefix decrement operator. Subtract one second from self, then return the results. RWTime ooooppppeeeerrrraaaattttoooorrrr++++++++(int); PPPPaaaaggggeeee 3333 RRRRWWWWTTTTiiiimmmmeeee((((3333CCCC++++++++)))) RRRRWWWWTTTTiiiimmmmeeee((((3333CCCC++++++++)))) Postfix increment operator. Add one second to self, returning the initial value. RWTime ooooppppeeeerrrraaaattttoooorrrr--------(int); Postfix decrement operator. Subtract one second from self, returning the initial value. RWTime& ooooppppeeeerrrraaaattttoooorrrr++++====(unsigned long s); Add ssss seconds to self, returning self. RWTime& ooooppppeeeerrrraaaattttoooorrrr----====(unsigned long s); Subtract ssss seconds from self, returning self. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr FFFFuuuunnnnccccttttiiiioooonnnnssss RWCString aaaassssSSSSttttrrrriiiinnnngggg(char format = ' ',const RWZone& = RWZone::local(), const RWLocale& = RWLocale::global()) const; Returns self as a string, formatted by the RRRRWWWWLLLLooooccccaaaalllleeee argument, with the time zone adjusted according to the RRRRWWWWZZZZoooonnnneeee argument. Formats are as defined by the standard C library function ssssttttrrrrffffttttiiiimmmmeeee(((()))). The default format is the date followed by the time: "%%%%xxxx %%%%XXXX". The exact format of the date and time returned is dependent upon the implementation of ssssttttrrrrffffttttiiiimmmmeeee(((()))) available. For more information, look under RRRRWWWWLLLLooooccccaaaalllleeee. RWCString aaaassssSSSSttttrrrriiiinnnngggg(char* format,const RWZone& = RWZone::local(), const RWLocale& = RWLocale::global()) const; Returns self as a string, formatted by the RRRRWWWWLLLLooooccccaaaalllleeee argument, with the time zone adjusted according to the RRRRWWWWZZZZoooonnnneeee argument. Formats are as defined by the standard C library function ssssttttrrrrffffttttiiiimmmmeeee(((()))). RWBoolean bbbbeeeettttwwwweeeeeeeennnn(const RWTime& a, const RWTime& b) const; Returns TTTTRRRRUUUUEEEE if RRRRWWWWTTTTiiiimmmmeeee is between aaaa and bbbb, inclusive. PPPPaaaaggggeeee 4444 RRRRWWWWTTTTiiiimmmmeeee((((3333CCCC++++++++)))) RRRRWWWWTTTTiiiimmmmeeee((((3333CCCC++++++++)))) size_t bbbbiiiinnnnaaaarrrryyyySSSSttttoooorrrreeeeSSSSiiiizzzzeeee() const; Returns the number of bytes necessary to store the object using the global function RWFile& operator<<(RWFile&, const RWTime&); int ccccoooommmmppppaaaarrrreeeeTTTToooo(const RWTime* t) const; Comparison function, useful for sorting times. Compares self to the RRRRWWWWTTTTiiiimmmmeeee pointed to by tttt and returns: 0 if self == *tttt; 1 if self > *tttt; -1 if self < *tttt; void eeeexxxxttttrrrraaaacccctttt(struct tm*,const RWZone& = RWZone::local()) const; Fills all members of the ssssttttrrrruuuucccctttt ttttmmmm argument, adjusted to the time zone specified by the RRRRWWWWZZZZoooonnnneeee argument. If the time is invalid, the ssssttttrrrruuuucccctttt ttttmmmm members are all set to -1. Note that the encoding of ssssttttrrrruuuucccctttt ttttmmmm members is different from that used in RRRRWWWWTTTTiiiimmmmeeee and RRRRWWWWDDDDaaaatttteeee functions. unsigned hhhhaaaasssshhhh() const; Returns a suitable hashing value. unsigned hhhhoooouuuurrrr(const RWZone& zone = RWZone::local()) const; Returns the hour, adjusted to the time zone specified. unsigned hhhhoooouuuurrrrGGGGMMMMTTTT() const; Returns the hour in UTC (GMT). PPPPaaaaggggeeee 5555 RRRRWWWWTTTTiiiimmmmeeee((((3333CCCC++++++++)))) RRRRWWWWTTTTiiiimmmmeeee((((3333CCCC++++++++)))) RWBoolean iiiissssDDDDSSSSTTTT(const RWZone& zone = RWZone::local()) const; Returns TTTTRRRRUUUUEEEE if self is during Daylight-Saving Time in the time zone given by zzzzoooonnnneeee, FFFFAAAALLLLSSSSEEEE otherwise. RWBoolean iiiissssVVVVaaaalllliiiidddd() const; Returns TTTTRRRRUUUUEEEE if this is a valid time, FFFFAAAALLLLSSSSEEEE otherwise. RWTime mmmmaaaaxxxx(const RWTime& t) const; Returns the later time of self or tttt. RWTime mmmmiiiinnnn(const RWTime& t) const; Returns the earlier time of self or tttt. unsigned mmmmiiiinnnnuuuutttteeee(const RWZone& zone = RWZone::local()) const; Returns the minute, adjusted to the time zone specified. unsigned mmmmiiiinnnnuuuutttteeeeGGGGMMMMTTTT() const; Returns the minute in UTC (GMT). unsigned sssseeeeccccoooonnnndddd() const; Returns the second; local time or UTC (GMT). unsigned long sssseeeeccccoooonnnnddddssss() const; Returns the number of seconds since 00:00:00 January 1, 1901 UTC. PPPPaaaaggggeeee 6666 RRRRWWWWTTTTiiiimmmmeeee((((3333CCCC++++++++)))) RRRRWWWWTTTTiiiimmmmeeee((((3333CCCC++++++++)))) Static Public Member Functions static RWTime bbbbeeeeggggiiiinnnnDDDDSSSSTTTT(unsigned year, const RWZone& zone = RWZone::local()); Return the start of Daylight-Saving Time (DST) for the given year, in the given time zone. Returns an "invalid time" if DST is not observed in that year and zone. static RWTime eeeennnnddddDDDDSSSSTTTT(unsigned year, const RWZone& = RWZone::local()); Return the end of Daylight-Saving Time for the given year, in the given time zone. Returns an "invalid time" if DST is not observed in that year and zone. static unsigned hhhhaaaasssshhhh(const RWTime& t); Returns the hash value of tttt as returned by tttt....hhhhaaaasssshhhh(((()))). static RWTime nnnnoooowwww(); Returns the present time. RRRReeeellllaaaatttteeeedddd GGGGlllloooobbbbaaaallll OOOOppppeeeerrrraaaattttoooorrrrssss RWTime ooooppppeeeerrrraaaattttoooorrrr++++(const RWTime& t, unsigned long s); RWTime ooooppppeeeerrrraaaattttoooorrrr++++(unsigned long s, const RWTime& t); Returns an RRRRWWWWTTTTiiiimmmmeeee ssss seconds greater than tttt. RWTime ooooppppeeeerrrraaaattttoooorrrr----(const RWTime& t, unsigned long s); Returns an RRRRWWWWTTTTiiiimmmmeeee ssss seconds less than tttt. RWBoolean ooooppppeeeerrrraaaattttoooorrrr<<<<(const RWTime& t1, const RWTime& t2); Returns TTTTRRRRUUUUEEEE if tttt1111 is less than tttt2222. PPPPaaaaggggeeee 7777 RRRRWWWWTTTTiiiimmmmeeee((((3333CCCC++++++++)))) RRRRWWWWTTTTiiiimmmmeeee((((3333CCCC++++++++)))) RWBoolean ooooppppeeeerrrraaaattttoooorrrr<<<<====(const RWTime& t1, const RWTime& t2); Returns TTTTRRRRUUUUEEEE if tttt1111 is less than or equal to tttt2222. RWBoolean ooooppppeeeerrrraaaattttoooorrrr>>>>(const RWTime& t1, const RWTime& t2); Returns TTTTRRRRUUUUEEEE if tttt1111 is greater than tttt2222. RWBoolean ooooppppeeeerrrraaaattttoooorrrr>>>>====(const RWTime& t1, const RWTime& t2); Returns TTTTRRRRUUUUEEEE if tttt1111 is greater than or equal to tttt2222. RWBoolean ooooppppeeeerrrraaaattttoooorrrr========(const RWTime& t1, const RWTime& t2); Returns TTTTRRRRUUUUEEEE if tttt1111 is equal to tttt2222. RWBoolean ooooppppeeeerrrraaaattttoooorrrr!!!!====(const RWTime& t1, const RWTime& t2); Returns TTTTRRRRUUUUEEEE if tttt1111 is not equal to tttt2222. ostream& ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(ostream& s, const RWTime& t); Outputs the time tttt on oooossssttttrrrreeeeaaaammmm ssss, according to the locale imbued in the stream (see class RRRRWWWWLLLLooooccccaaaalllleeee), or by RRRRWWWWLLLLooooccccaaaalllleeee::::::::gggglllloooobbbbaaaallll(((()))) if none. RWvostream& ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(RWvostream&, const RWTime& t); RWFile& ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(RWFile&, const RWTime& t); Saves RRRRWWWWTTTTiiiimmmmeeee tttt to a virtual stream or RRRRWWWWFFFFiiiilllleeee, respectively. RWvistream& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWvistream&, RWTime& t); RWFile& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWFile&, RWTime& t); Restores an RRRRWWWWTTTTiiiimmmmeeee into tttt from a virtual stream or RRRRWWWWFFFFiiiilllleeee, respectively, PPPPaaaaggggeeee 8888 RRRRWWWWTTTTiiiimmmmeeee((((3333CCCC++++++++)))) RRRRWWWWTTTTiiiimmmmeeee((((3333CCCC++++++++)))) replacing the previous contents of tttt. PPPPaaaaggggeeee 9999